//
// Created by wangjunjun on 2024/9/28
//

#ifndef ALARMIMAGE_H
#define ALARMIMAGE_H
/*
 * ＠function:获取异常告警图片
 * */
#include <opencv2/opencv.hpp>
#include <iostream>
#include <memory>
#include <mutex>
#include <vector>
#include <string>
#include <time.h>
#include "sdk/siyi_camera.hpp"
#include <thread>

#include "ros/ros.h"
#include "std_msgs/Float32.h"

#define  MAX_RETRY_CONNECT_CNT (5)
using namespace cv;
using namespace std;
class CAlarmImage {

public:
    //设置单例模式获取资源数据
    static std::shared_ptr<CAlarmImage> GetInStance();
    void init();
    bool start();
    void initCamera(const std::string& cameraIp, int port);
    void processFrames(VideoCapture& cap);
    std::string getCurrentTimeString();
    std::string createSaveDirectory();
    VideoCapture reconnectVideoStream(const std::string& stream);
    void processFrame(Mat& frame, int maxTemperature, int maxX, int maxY);
    void saveFrame(const Mat& frame, const string& savePath);

private:
    CAlarmImage();
    ~CAlarmImage();
private:
    float m_Distance;  // 距离变量，用于保存 /dist 话题数据
    ros::NodeHandle nh;
    ros::Subscriber distSubscriber;
    void distanceCallback(const std_msgs::Float32::ConstPtr& msg);
    
    static std::shared_ptr<CAlarmImage> m_Instance;
    static std::once_flag m_flag;
    siyi::Camera camera;
    vector<pair<Mat, time_t>> m_FrameHistory;
    std::string  m_VideoStream;
    std::string  m_Sn;
    int m_TemperatureThreshold;
    int m_port; // 控制端口
    std::string  m_cameraIp;  //相机IP
};


#endif //ALARMIMAGE_H
